package com.trippin.DB.entities;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.gson.annotations.Expose;

@PersistenceCapable
public class SharingRequest implements TrippinEntity, Serializable {

	private static final long serialVersionUID = 1L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	
	@Persistent
	@Expose
	private long id;
	
	@Persistent
	@Expose
	private long sharedEntityId;
	
	//the user that sent the request.
	@Persistent
	@Expose
	private long requestFromUser;	
	
	@Persistent
	@Expose
	private String title;
	
	@Persistent
	@Expose
	private String description;
	
	@Persistent
	@Expose
	private Date start;
	
	@Persistent
	@Expose
	private Date end;
	
	@Persistent
	@Expose
	private Date sentOn;

	
	public SharingRequest(TrippinEntity entity, long requestFromUser) {
		this.requestFromUser = requestFromUser;
		this.sentOn = new Date();
		if(entity instanceof TripEntity) {
			TripEntity sharedTrip = (TripEntity)entity;
			this.sharedEntityId = sharedTrip.getId();
			this.title = sharedTrip.getTitle();
			this.description = sharedTrip.getNotes();
			this.start = sharedTrip.getStart();
			this.end = sharedTrip.getEnd();
			this.id = -1;
		}
		
	}
	
	public long getId() {
		if(id < 0) {
			return key.getId();
		}
		return id;
	}

	public void setId() {
		this.id = key.getId();
	}

	public Key getKey() {
		return key;
	}
	
	public long getShareEntityId() {
		return sharedEntityId;
	}

	public long getShareWith() {
		return requestFromUser;
	}

	public void setShareWith(long shareWith) {
		this.requestFromUser = shareWith;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getDescription() {
		return description;
	}


	public void setDescription(String description) {
		this.description = description;
	}

	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getEnd() {
		return end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public Date getSentOn() {
		return sentOn;
	}

 
}
